package com.itheima.ydd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.Config;
import com.itheima.ydd.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author yan.zhou
 * @date 2022/2/16
 */
@RestController
@RequestMapping("sys_config")
public class ConfigController {
    /**
     * update   POST    已测
     * all      GET     已测
     */
    @Autowired
    private ConfigService configService;

    /**
     * 所有配置数据
     * @return
     */
    @GetMapping("all")
    public ResultData all() {

        Map<String, Object> map = configService.all();
        return ResultData.ok("", map);
    }

    /**
     *
     * @param list
     * @return
     */
    @PostMapping("/update")
    public ResultData add(@RequestBody List<Config> list){
        for (Config config : list) {
//            LambdaUpdateWrapper<Config> wrapper=new LambdaUpdateWrapper<>();
//            wrapper.eq(Config::getId,config.getId());

            configService.updateById(config);
        }
        return ResultData.ok("","保存成功");
    }
}